/* 
 * File:   main.c
 * Author: gustavo
 *
 * Created on January 6, 2012, 4:29 AM
 */

#include <stdio.h>
#include <stdlib.h>

#include <gtk/gtk.h>

#include "v4li/v4li.h"
#include "camcal.h"

#include <imp/image/io/imageio.h>
#include <imp/image/draw/draw.h>
#include <imp/image/morphology/immorph.h>

 /**
 * @param argc
 * @param argv
 * @return 
 */
void proc(void) {
	ImpImage * RGB = NULL;
	ImpImage * GRAY = NULL;
	
	ImpMatrix * Mat = NULL;
	ImpMatrix * Thin = NULL;
	ImpMatrix * Feat = NULL;
	
	unsigned char uk;
	char k;
	
	k = -1;
	uk = 0 | k;
	uk >>= 1;
	
	
	RGB = imp_image_read_ppm("bac.ppm");
	imp_image_rgb2gray( RGB, &GRAY);
	
	imp_image_gray2mat(GRAY, &Mat);
	
	int x = imp_image_label( Mat, &Thin, 255.0 );
	
	imp_image_label_analisys( Thin, x, &Feat);
	
	imp_matrix_print(Feat);
	
	printf("Number of labels: %d\n",x);
	
	int i;
	ImpDraw draw = imp_draw_create(GRAY);
	imp_draw_set_fg( &draw, imp_color_gray(50));
	for( i = 0; i < x; i++) {
		imp_draw_cross( &draw, Feat->data[ i*Feat->columns + 8], Feat->data[ i*Feat->columns + 9], 3 );
	}
	imp_image_save_pgm(GRAY, "test.pgm");
	
	imp_image_save_matrix_as_image( Thin, TRUE, "thin.pgm");
}
 

int main(int argc, char** argv) {
/*
	proc();
	return 0;
*/
	GtkWidget *window;

	gtk_init(&argc, &argv);

	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
	gtk_container_set_border_width(GTK_CONTAINER(window), 10);

	CamCal * cc = cc_new();
	gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(cc->box));

	gtk_widget_show_all(window);
	gtk_main();


	return (EXIT_SUCCESS);
}

